home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Pascal Super Library
/
Pascal Super Library (CW International)(1997).bin
/
LIBRARY
/
PAS_0693
/
FEXISTS.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-06-30
|
2KB
|
64 lines
{─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
Msg : 169 of 245
From : Sean Palmer 1:104/123.0 15 Jun 93 00:31
To : All
Subj : File Exist funtion again
────────────────────────────────────────────────────────────────────────────────
I just ran some timings, which are gonna be affected by SMARTDRV.EXE
being loaded, but I took that into account (ran multiple times on same
file, and took timings on second/subsequent runs, to make sure always
got cache hits)
What I got was that FileExists below and my modified version of that
fileExist3 function that's been floating around this echo for a while
(no bug) both run neck and neck... it's amazing... both are slightly
faster than FileExist2 and lots lots faster than the 'reset,
fileExist=(ioresult=0)' type thing that most people still seem to use...
I'd recommend using the first one below as it's really short...}
uses dos;
function fileExists(var s:string):boolean;begin {tied for fastest}
fileExists:=fSearch(s,'')<>'';
end;
function fileExist2(var s:string):boolean;var r:searchrec;begin {2nd}
findfirst(s,anyfile,r);
fileExist2:=(dosError=0);
end;
function fileExist3(var s:string):boolean; assembler;asm
{tied for fastest}
push ds
lds si,s {need to make ASCIIZ}
cld
lodsb {get length; si now points to first char}
xor ah,ah
mov bx,ax
mov al,[si+bx] {save byte before placing terminating null}
push ax
mov byte ptr [si+bx],0
mov dx,si
mov ax,$4300 {get file attributes}
int $21
mov al,1 {if carry set, fail}
pop dx
mov [si+bx],dl {restore byte}
pop ds
end;
function fileExist4(var s:string):boolean; var f:file;begin {slowest}
assign(f,s);
{$I-}
reset(f);
{$I+}
if ioresult=0 then begin
close(f);
fileExist4:=true;
end
else fileExist4:=false;
end;
const s:string='\autoexec.bat';